/**
 * @file      ithread.h
 * @copyright Copyright (c) 2020, ZCW Co., Ltd. All Rights Reserved.
 * @brief     brief
 * @author    caiwang213@qq.com
 * @date      2020-05-16 23:07:19
 *
 * @note
 *  ithread.h defines
 */
#ifndef __ITHREAD_H__
#define __ITHREAD_H__
#include "os.h"

#ifdef _WIN32
typedef HANDLE           THREAD;
typedef CRITICAL_SECTION MUTEX;
typedef HANDLE           COND;
typedef HANDLE           SEM;

#else

#include <pthread.h>
/* #include <semaphore.h> */
#include <sys/time.h>
typedef pthread_mutex_t  MUTEX;
typedef pthread_cond_t   COND;
/* typedef sem_t            SEM; */
typedef pthread_t        THREAD;
#endif

namespace log4x
{
class ithread
{
public:
    virtual void        sleep(long ms) = 0;

    virtual THREAD      start(void* (*entry)(void*, int), void* data, int id) = 0;
    virtual void        end(THREAD& t, int timeout = 0) = 0;
    virtual void        detach(THREAD& t) = 0;
    virtual long        tid() = 0;

    virtual void      * get_tls()          = 0;
    virtual void        set_tls(void* val) = 0;

    virtual void        init_mutex(MUTEX& mtx)   = 0;
    virtual void        uninit_mutex(MUTEX& mtx) = 0;
    virtual void        lock(MUTEX& mtx)         = 0;
    virtual void        unlock(MUTEX& mtx)       = 0;

protected:
    virtual ~ithread() {}
};
}
#endif
